class Event {

    constructor() {
        this.handlers = {}
    }

    on(type, handler) {
        if (typeof this.handlers[type] === 'undefined') {
            this.handlers[type] = []
        }
        this.handlers[type].push(handler)
        console.log(`${this.handlers[type].length} 同学说 ${type}`);
    }

    emit(type, message) {
        if (this.handlers[type] instanceof Array) {
            let handlers = this.handlers[type]
            for (const handler of handlers) {
                handler(handlers.indexOf(handler) + 1, message)
            }
        }
    }
}

let event = new Event()


event.on('你在干嘛', (who, message) => console.log(`回复 ${who} 同学: ${message}`))
event.on('你在干嘛', (who, message) => console.log(`回复 ${who} 同学: ${message}`))
event.on('你在干嘛', (who, message) => console.log(`回复 ${who} 同学: ${message}`))
event.on('你在干嘛', (who, message) => console.log(`回复 ${who} 同学: ${message}`))
event.on('你好哇', (who, message) => console.log(`回复 ${who} 同学: ${message}`))

event.emit('你在干嘛', '呵呵，我去洗澡了。等等聊。')
event.emit('你好哇', '你好呀！')